<template>
  <router-link :class="{good: true, hover}"
               :style="`width: ${width}px`"
               :to="`/product/${good.id}`">
    <img v-lazy="good.picture"
         :style="`width: ${imgSize}px;height: ${imgSize}px`"/>
    <p class="ellipsis">{{ good.name }}</p>
    <p class="ellipsis">{{ good.desc }}</p>
    <p>￥{{ good.price }}</p>
  </router-link>
</template>

<script lang="ts"
        setup>
import type {Good} from '@/types/good'
import {toRefs} from 'vue'

let props = withDefaults(defineProps<{
  data: Good,
  width?: number,
  imgSize?: number,
  hover?: boolean
}>(), {
  width: 220,
  imgSize: 160,
  hover: true
})
let {data: good} = toRefs(props)
</script>

<style lang="less"
       scoped>
.good {
  width: 220px;
  background-color: white;
  padding: 20px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;

  img {
    object-fit: cover;
  }

  p {
    width: 100%;
    margin-top: 10px;
    text-align: center;

    &:nth-of-type(1) {
      font-size: 16px;
      color: #666666;
    }

    &:nth-of-type(2) {
      color: #999999;
    }

    &:nth-of-type(3) {
      font-size: 20px;
      color: @priceColor;
    }
  }


}

.hover:hover {
  .hoverShadow();
}
</style>